﻿    $(document).on('pagebeforeshow', '#options', function(){  
        setStyle("avtorizate");
        
        var log = window.localStorage.getItem("login");
        if (log != null ){
        	document.getElementById("logininput").value = log;
        }else{
        	var log = window.sessionStorage.getItem("login");
        	if (log != null){
        		document.getElementById("logininput").value = log;
        	}
        	else {
        		$('#esc').hide();
        	}
        }
    });  
    
    //press button avtirizate
    function butPress(){
    	login = document.getElementById("logininput").value;
    	pas = MD5(document.getElementById("passinput").value);
    	pas = MD5(pas);
    	$.mobile.loading('show');   
        var http = "http://anibox.me/api.php?task=user_exists&name="+login+"&password="+pas;
        $.getJSON(http, parseJson);
    }
    
    function parseJson(data){
    	if (String(data) == 'true'){
    		alert("вы авторизованы");
    		if (document.getElementById("checkbox-1").value == 'on'){
        		window.localStorage.setItem("login", login);
    			window.localStorage.setItem("password", pas);
        	}else{
        		window.sessionStorage.setItem("login", login);
    			window.sessionStorage.setItem("password", pas);
        	}
			
			$('#esc').show();
    	}else{
    		alert("неверный логин/пароль");
    	}    	
    }
    
    function exitPress(){
    	$('#esc').hide();
    	document.getElementById("logininput").value = "";
    	document.getElementById("passinput").value = "";
    	
        window.localStorage.clear();
		window.localStorage.clear();
		
		window.sessionStorage.clear();
		window.sessionStorage.clear();
    }